<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
    <style>
      . {
        margin: 0;
        padding: 0;
      }

      html,
      body {
        width: 100%;
        height: 100%;
      }

      .container {
        width: 100%;
        height: 100%;
        background: url(../assets/images/background.jpg) no-repeat;
        background-size: cover;
      }

      .box {
        width: 1920px;
        height: 1080px;
        background: red;

        transform-origin: left top;

        position: fixed;
        left: 50%;
        top: 50%;
      }

      .top {
        width: 100px;
        height: 100px;
        background: blue;
        margin-left: 50px;
      }

      .bottom {
        width: 100px;
        height: 100px;
        background: hotpink;
        margin-left: 50px;
        margin-top: 100px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box">
        <div class="top">我是祖国人</div>
        <div class="bottom">我是案例</div>
      </div>
    </div>
  </body>
</html>
<script>
  const box = document.querySelector('.box')
  // 初始化
  box.style.transform = `scale(${getScale()})  translate(-50%,-50%)`
  // 监听窗口大小变化
  window.onresize = () => {
    box.style.transform = `scale(${getScale()})  translate(-50%,-50%)`
  }

  // 计算缩放比例
  function getScale(w = 1920, h = 1080) {
    const widthProportion = window.innerWidth / w
    const heightProportion = window.innerHeight / h

    return widthProportion < heightProportion
      ? widthProportion
      : heightProportion
  }
</script>
